package pers.cz.connect;

import pers.cz.connect.redis.RedisConnection;
import pers.cz.db.redis.RedisPoolFactory;
import redis.clients.jedis.JedisPool;

/**
 * @program: postgirl-collection-client
 * @description: 抽象连接工厂
 * @author: Cheng Zhi
 * @create: 2022-07-31 11:59
 **/
public class ConnectionFactory implements AutoCloseable{

    private IConnection createConnection(DBType type) {
        IConnection connection = null;

        if (type.equals(DBType.REDIS)) {
            // 如果是redis，需要先创建一个RedisPool
            JedisPool jedisPool = RedisPoolFactory.getJedisPool();
            connection = new RedisConnection(jedisPool);
        } else if (type.equals(DBType.KAFAKA)) {
            // kafaka操作
        } else if (type.equals(DBType.MQ)) {
            // mq操作
        }

        return connection;
    }

    public IConnection getConnection(DBType type) {

        IConnection connection = createConnection(type);

        return connection;
    }

    @Override
    public void close() throws Exception {

    }
}
